package com.community.web.controller.server;

import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.core.page.TableDataInfo;
import com.community.common.utils.SecurityUtils;
import com.community.domain.OrderEntity;
import com.community.service.OrderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.OrderComparator;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    private static final Logger log = LogManager.getLogger(OrderController.class);
    @Autowired
    private OrderService OrderService;

    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderEntity OrderEntity) {
        startPage();
        List<OrderEntity> list = OrderService.selectOrder(OrderEntity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('order:order:add')")
    @PostMapping("/addOrder")
    public AjaxResult addServeType(@RequestBody OrderEntity OrderEntity) {
        return toAjax(OrderService.addOrder(OrderEntity));
    }

    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @PutMapping("/editOrder")
    public AjaxResult editOrder(@Validated @RequestBody OrderEntity OrderEntity) {
        return toAjax(OrderService.editOrder(OrderEntity));
    }

    @PreAuthorize("@ss.hasPermi('order:order:remove')")
    @DeleteMapping("{id}")
    public AjaxResult deleteOrder(@PathVariable @RequestBody int id) {
        return toAjax(OrderService.deleteOrder(id));
    }
    @PreAuthorize("@ss.hasPermi('order:order:receive')")
    @PutMapping("/receiveOrder")
    public AjaxResult receiveOrder(@Validated @RequestBody OrderEntity OrderEntity) {
        return toAjax(OrderService.receiveOrder(OrderEntity));
    }

    @PostMapping("/getOrderType")
    public OrderEntity getOrderType(OrderEntity order) {
        return OrderService.selectOrderType(order);
    }
    @PreAuthorize("@ss.hasPermi('order:order:sum')")
    @GetMapping("/sum")
    public AjaxResult authRole(OrderEntity orderEntity)
    {
        int num=OrderService.countnumber();
        AjaxResult ajax = AjaxResult.success();
        ajax.put("num", num);
        System.out.println(num);
        return ajax;
    }
}

